

export default {
    name: "taskCondition",
    data() {
        return {
            allItemList: [],
            showItemList: [],
            formShow: false,
            ids: [],
            users: [],
            searchForm: {
                name: '',
                code: ''
            },
            tableData: [],
            pager: {
                page: 0,
                size: 20,
                total: 0
            },
            dialogFormVisible: false,
            viewHide: false,
            editCode: false,
            taskCondition: {
                name: '',
                code: '',
                strValue: '',
                isUse: '1',
                remarks: '',
            },
            dialogTitle: '新增条件',
            entityId: '',
            useable: true,
        }
    },
    computed: {
        height() {
            return `calc(100vh - 350px)`;
        }
    },
    mounted() {
        this.getusers();
        this.getList();
    },
    methods: {
        getusers() {
            let params = {};
            this.$api
                .formPost("/api/auth/sysuser/doGetList", params)
                .then(res => {
                    if (res.retHead.code == "0000000") {
                        this.users = res.retBody.list;
                    }
                });
        },
        // 关闭弹窗
        handleFormClose: function () {
            this.searchForm = {
                name: '',
                code: ''
            };
            this.taskCondition = {
                id: '',
                name: '',
                code: '',
                strValue: '',
                isUse: '1',
                remarks: '',
            };
            this.viewHide = false;
            this.editCode = false;
            this.dialogTitle = '新增条件';
            this.dialogFormVisible = false;
            this.entityId = '';
        },
        // 查看
        view: function (item) {
            this.dialogTitle = '查看条件';
            this.dialogFormVisible = true;
            this.viewHide = true;
            this.editCode = true;
            this.taskCondition = {
                name: item.name || '',
                code: item.code || '',
                strValue: item.strValue || '',
                isUse: item.isUse || '1',
                remarks: item.remarks || '',
            }
        },
        // 修改
        edit: function (item) {

            this.dialogTitle = '修改条件';
            this.dialogFormVisible = true;
            this.editCode = false;
            this.entityId = item.id;
            this.taskCondition = {
                name: item.name || '',
                code: item.code || '',
                strValue: item.strValue || '',
                isUse: item.isUse || '1',
                remarks: item.remarks || '',
            };

        },
        // 删除
        deleteByIds: function () {
            // alert(this.ids);
            if (this.ids.length > 0) {
                let idsStr = "";
                for (let i = 0; i < this.ids.length; i++) {
                    idsStr += this.ids[i].id + ",";
                }
                idsStr = idsStr.substring(0, idsStr.length - 1);
                //alert(idsStr);
                this.delete(idsStr);
            } else {
                this.$message({
                    type: 'warning',
                    message: '请先选择数据!'
                });
            }

        },
        delete: function (id) {
            let params = {};
            let ids = id.split(",");
            for (var i = 0; i < ids.length; i++) {
                let list = {};
                list.id = ids[i];
                params[i] = list;
            }
            this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$api.post('/api/biz/flowTaskCondition/delBatchTaskCondition', params).then(res => {
                    if (res.retHead.code === '0000000') {
                        if (res.retBody.status === "0") {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.getList();
                        } else {
                            this.$message({
                                type: "error",
                                message: res.retBody.message
                            });
                        }

                    } else {
                        this.$message({
                            type: "error",
                            message: res.retHead.message
                        });
                    }
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        // 保存
        doSave: function () {
            let user = JSON.parse(sessionStorage.getItem("user"));
            let params = {};
            params = {
                name: this.taskCondition.name,
                code: '',
                strValue: this.taskCondition.strValue,
                isUse: this.taskCondition.isUse || '1',
                remarks: this.taskCondition.remarks || '',
                createUser: user.id,
                createDate: new Date(),
            };
            if (this.entityId == '') {

            } else {
                params.id = this.entityId;
            }
            this.$api.post('/api/biz/flowTaskCondition/saveTaskCondition', params).then(res => {
                if (res.retHead.code === '0000000') {
                    if (res.retBody.status === "0") {
                        this.handleFormClose();
                        this.$message({
                            type: 'success',
                            message: '保存成功!'
                        });
                        this.getList();
                    } else {
                        this.$message({
                            type: "error",
                            message: res.retBody.message
                        });
                    }

                } else {
                    this.$message({
                        type: "error",
                        message: res.retHead.message
                    });
                }

            });
        },
        // 获取条件列表
        getList: function () {
            let params = {
                page: this.pager.page === 0 ? this.pager.page : this.pager.page - 1,
                size: this.pager.size,
                name: this.searchForm.name,
                code: this.searchForm.desc
            };
            this.$api.post('/api/biz/flowTaskCondition/getTaskConditionList', params).then(res => {
                if (res.retHead.code === '0000000') {
                    if (res.retBody.status === "0") {
                        this.tableData = res.retBody.data.resContent
                        this.pager.total = res.retBody.data.total
                    } else {
                        this.$message({
                            type: "error",
                            message: res.retBody.message
                        });
                    }

                } else {
                    this.$message({
                        type: "error",
                        message: res.retHead.message
                    });
                }
            });
        },
        handleSelectionChange: function (val) {
            this.ids = val;
            //console.log(this.ids);
        },
        stateChange: function () {
            this.taskCondition.isUse = val == true ? "1" : "0";
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pager.size = val;
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.pager.page = val;
        },
    }
}
